package org.leviatan.dataharbour.jclient;

import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.TreeSet;
import java.util.Vector;

import org.leviatan.dataharbour.core.admin.DataHarbourAdminService;
import org.leviatan.dataharbour.core.model.DataSource;
import org.leviatan.dataharbour.core.model.HarbourRequest;
import org.leviatan.dataharbour.core.model.PersistenceResource;
import org.leviatan.dataharbour.jclient.local.LocalServiceProxy;
import org.leviatan.definator.core.model.Table;

/**
 * Client interface for admin communication with DataHarbour. This interface
 * is for both remote and local communication making communication transparent
 * for clients.
 * 
 * @author Leviatan
 *
 */
public  abstract class DataHarbourServiceProxy implements DataHarbourAdminService {
	
	
	/**
	 * Builds a proxy to use for remote communication with DataHarbour.
	 * 
	 * @return A RemoteServiceProxy.
	 */
	public static DataHarbourServiceProxy buildRemoteProxy() {
		return null;
	}
	
	/**
	 * Builds a proxy to use for local, i.e. same JRE, communication with DataHarbour.
	 * 
	 * @return	A LocalServiceProxy.
	 */
	public static DataHarbourServiceProxy buildLocalProxy() {
		return new LocalServiceProxy();
	}

	
	// main loads
	///////////////////////////////////////////////////////////////////////////
	
	/**
	 * Loads a specified configuration into DataHarbour.
	 */
	public abstract void loadConfiguration(String filePath);

	/**
	 * Loads all DataHarbours data models from its file system.
	 */
	public abstract void loadModels();

	/**
	 * Loads all DataHarbours mappings from its file system.
	 */
	public abstract void loadRegisterMappings();

	/**
	 * Saves all DataHabours data models to its file system.
	 */
	public abstract void saveModels();

	/**
	 * Saves DataHarbours register mappings to its file system.
	 */
	public abstract void saveRegister();

	
	
	///////////////////////////////////////////////////////////////////////////
	
	/**
	 * Gets all unpersisted HarbourRequests from DataHarbour.
	 * @return	A map of <(String) HarbourRequest id, HarbourRequest>
	 */
	public abstract Map getAllUnpersistedHarbourRequests();
	
	/**
	 * Gets the specified DataSource from DataHarbour.
	 * @param id	A DataSource id.
	 * @return	A DataSource object.
	 */
	public abstract DataSource getDataSource(String id);
	
	/**
	 * Removes specified DataSource from DataHarbour.
	 * @param id	A DataSource id.
	 */
	public abstract void removeDataSource(String id);
	
	/**
	 * Gets all DataSources from Dataharbour.
	 * @return	A Map of <(String) DataSource id, DataSource>
	 */
	public abstract Map getAllDataSources();

	/**
	 * Gets the unpersisted HarbourRequest objects mapped to specified sender.
	 * @return	A Collection of HarbourRequest objects. 
	 */
	public abstract Collection getSendersUnpersistedHarbourRequests(String senderId);

	/**
	 * Gets specified HarbourRequest from DataHarbour.
	 * @param	reqId	A HarbourRequest id.
	 * @return	A HarbourRequest object.
	 */
	public abstract HarbourRequest getUnpersistedHarbourRequest(String reqId);

	/**
	 * Removes specified HarbourRequest from DataHarbour.
	 * @param	reqId	A HarbourRequest id.
	 */
	public abstract void removeUnpersistedHarbourRequest(String reqId);

	/**
	 * Gets the Definator Table objects mapped to specified DataSource.
	 * @return	A Vector of Definator Table objects.
	 */
	public abstract Vector getDataSourcesDefs(String dataSourceId);

	/**
	 * Gets the Persistence Resource ids mapped to specified DataSource.
	 * @param	dataSourceId	A DataSource id.
	 * @return	A Vector of Persistence Resource ids.
	 */
	public abstract TreeSet<String> getDataSourcesPersistenceResourceKeys(String dataSourceId);

	/**
	 * Unmapped specified Definator Table id from specified DataSource id.
	 * @param	dataSourceId	The DataSource id to unmap.
	 * @param	defId	The Definator Table id to unmap.
	 */
	public abstract void removeDefFromDataSource(String dataSourceId, String defId);

	/**
	 * 
	 */
	public abstract void removePersistenceResourceFromDataSource(String dataSourceId, String persResId);

	public abstract void addDefToDataSource(String dsId, String defId);

	public abstract void addPersistenceResourceToDataSource(String dsId, String perResId);

	public abstract Collection<Table> getAllVirtualStructures();

	public abstract void saveDataSource2DefinitionsMappings();

	public abstract void saveDataSource2PersistenceResourceMappings();

	public abstract HashMap getAllPersistenceResources();

	public abstract TreeSet<String> getDataSourcesPersistenceResources(String dataSourceId);

	public abstract String getNewUniqueId();

	public abstract String addDataSource(DataSource ds);

	public abstract String createDataSource(String name);

	public abstract void saveDataSources();

	public abstract void savePersistenceResources();

	public abstract void saveUnpersistedHarbourRequests();

	public abstract PersistenceResource getPersistenceResource(String persResId);

	public abstract void removePersistenceResource(String persResId);

	public abstract void updateHibernatePersistenceResource(String id, String name, String hibConf);
	
	public abstract void updatePersistenceResource(String id, String name);

	public abstract String createPersistenceResource(String name, String type);
	
	public abstract String createHibernatePersistenceResource(String name, String confString);

	public abstract void updateDataSource(String id, String name);
	
	
	
	
	
}
